/**
 * 本地基础服务
 * @author TianGanLin
 */
(function () {
    /**
     * 系统常量服务
     *
     * @author TianGanLin
     * @version v1.0.0
     * @since 2017-08-22
     */
    app.service('Constant', function () {
        // 国际化模块
        this.I18N = {
            TYPE: { // 类型(国际化对象)
                CATEGORY_ROOT: 0,
                // 菜单
                MENU: 1,
                // 字典
                DICTIONARY: 2,
                // 字典类型
                CATEGORY: 3
            }
        };
        // 字典模块
        this.DICT = {
            CATEGORY_ROOT: 'ess.dict.category.root',
            CATEGORY: 'ess.dict.category',
            PATROL_CATEGORY: 'patrol.category', // 巡查类型
            PATROL_STATUS: 'patrol.status' // 巡查状态
        };
        // 巡查
        this.PATROL = {
            // 状态
            STATUS: {
                CREATE: {name: '待完善', code: 'create', value: 1},
                REPORT: {name: '待验收', code: 'report', value: 2},
                THROUGH: {name: '已通过', code: 'through', value: 3},
                REFUSE: {name: '已退回', code: 'refuse', value: 4},
                FINISH: {name: '已完成', code: 'finish', value: 5}
            }
        };
        // 报告
        this.REPORT = {
            // 类型
            CATEGORY: {
                VISIT: {name: '回访', value: 1},
                REPLY: {name: '回复', value: 2},
                ACCEPT: {name: '验收', value: 3}
            }
        }
    });

    /**
     * 时间控件wdatepicker
     */
    app.directive('wdatePicker', function () {
        return {
            restrict: 'A',
            require: 'ngModel',
            link: function (scope, element, attr, ngModel) {
                function onpicked(dp) {
                    var date = dp.cal.getNewDateStr();
                    scope.$apply(function () {
                        ngModel.$setViewValue(date);
                    });
                }

                function oncleared() {
                    scope.$apply(function () {
                        ngModel.$setViewValue(undefined);
                    });
                }

                element.bind('click', function () {
                    var options = angular.extend(
                        {
                            oncleared: oncleared,
                            onpicked: onpicked
                        },
                        eval('(' + attr.wdatePicker + ')')
                    );
                    WdatePicker(options);
                });
            }
        };
    });
})();